<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>eshop</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../mui/css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/app.css" />
		<link rel="stylesheet" type="text/css" href="../../mui/css/icons-extra.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<div class="mui-input-row mui-search search">
				<input type="search" class="mui-input-clear index-search" placeholder="搜索商品名称">
			</div>
		</header>
		<nav class="mui-bar mui-bar-tab">
			<a id='home' class="mui-tab-item mui-active">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a id='sort' class="mui-tab-item">
				<span class="mui-icon mui-icon-email"></span>
				<span class="mui-tab-label">分类</span>
			</a>
			<a id='cart' class="mui-tab-item">
				<span class="mui-icon mui-icon-contact"></span>
				<span class="mui-tab-label">购物车</span>
			</a>
			<a id='user' class="mui-tab-item">
				<span class="mui-icon mui-icon-gear"></span>
				<span class="mui-tab-label">会员</span>
			</a>
		</nav>
		<div class="mui-content">
			<div id="slider" class="mui-slider">
				<div class="mui-slider-group mui-slider-loop" id="advertDiv">
					
				</div>
				<div class="mui-slider-indicator">
					<div class="mui-indicator mui-active"></div>
					<div class="mui-indicator"></div>
					<div class="mui-indicator"></div>
					<div class="mui-indicator"></div>
				</div>
			</div>
	
			<ul class="mui-table-view mui-grid-view">
				<li class="mui-table-view-cell mui-media mui-col-xs-4">
					<a href="detail.html"><img class="mui-media-object" src="../images/dog_1.jpg">
					</a>
				</li>
				<li class="mui-table-view-cell mui-media mui-col-xs-4">
					<a href="detail.html"><img class="mui-media-object" src="../images/dog_1.jpg">
					</a>
				</li>
				<li class="mui-table-view-cell mui-media mui-col-xs-4">
					<a href="detail.html"><img class="mui-media-object" src="../images/dog_1.jpg">
					</a>
				</li>
			</ul>
	
			<ul class="mui-table-view" id="goodsListDiv">
			</ul>
		</div>
	</body>
	<script src="../../mui/js/mui.min.js"></script>
	<script src="../../js/common.js"></script>
	<script src="../../js/ajax-common.js"></script>	
	<script src="../../js/jquery-2.1.1.min.js"></script>		
	<script type="text/javascript" charset="utf-8">
		mui.init({
			swipeBack: true//启用右滑关闭功能
		});
		/* 初始化数据 */
		mui.ready(function(){
			var url = "index";
			var success = function(response) {
				var advertList = response.advertList;
				var goodsList = response.goodsList;
				setAdvert(advertList);
				setGoodsList(goodsList);
			};
			ajaxFunc(url, success);
		})
		/* 设置广告位数据 */
		function setAdvert(advertList){
			var advHtml ="";
			if(advertList){
				advHtml = advHtml + setImageUrl(advertList[advertList.length-1].imageUrl);
				for(key in advertList){
					advHtml = advHtml + setImageUrl(advertList[key].imageUrl);
				}
				advHtml = advHtml + setImageUrl(advertList[0].imageUrl);
			}
			$('#advertDiv').html(advHtml);
			//定时轮播
			var slider = mui("#slider");
			slider.slider({
				interval: 5000
			});	
		}
		
		function setImageUrl(url){
			var imageDiv = '<div class="mui-slider-item mui-slider-item-duplicate"><a><img src="'+imageCxt+url
			+'" class = "index-advert-image"></a></div>';
			return imageDiv;
		}
		
		/* 设置商品列表数据 */
		function setGoodsList(goodsList){
			var goodsHtml ="";
			if(goodsList){
				for(key in goodsList){
					goodsHtml = goodsHtml + setGoods(goodsList[key]);
				}
			}
			$('#goodsListDiv').html(goodsHtml);
		}
		
		function setGoods(goods){
			var goodsDiv = '<li class="mui-table-view-cell mui-media"><a id= "'+goods.id+'"><img class="index-image mui-pull-left" src="'+
				imageCxt+goods.showImageUrl+'"><div class="mui-media-body"><textarea class="index-textarea" readonly="readonly">'+
				goods.title+'</textarea><h4><font color="#FF0000">'+goods.salePrice+'</font></h4></div></a></li>';
			return goodsDiv;
		}
		/* 商品列表点击跳转页面 */
		mui(".mui-table-view").on('tap', 'a', function() {
			var goodsId = this.getAttribute('id');
			mui.openWindow({
				id:'goodsDetail',
				url:'goods/goodsDetail.html',
			});
			window.localStorage.goodsId = goodsId; 
		});
		/*点击购物车标签*/
		document.getElementById("cart").addEventListener('tap',function(){
			mui.openWindow({
				id:'cart',
				url:'cart/cart.html'
			});
		});
		/*点击会员*/
		document.getElementById("user").addEventListener("tap",function(){
			mui.openWindow({
				id:'userInfo',
				url:'user/userInfo.html'
			});
		});
	</script>

</html>